/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.karla.webservices;

import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;


import java.io.File;
import java.util.Scanner;
import java.util.Set;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AddAxiom;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataFactory;
import org.semanticweb.owlapi.model.OWLIndividual;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.semanticweb.owlapi.reasoner.BufferingMode;
import org.semanticweb.owlapi.reasoner.ConsoleProgressMonitor;
import org.semanticweb.owlapi.reasoner.NodeSet;
import org.semanticweb.owlapi.reasoner.OWLReasonerConfiguration;
import org.semanticweb.owlapi.reasoner.SimpleConfiguration;

import uk.ac.manchester.cs.factplusplus.owlapiv3.FaCTPlusPlusReasoner;

/**
 *
 * @author usuario
 */
@WebService(serviceName = "EscribirDatosEstudiante")
public class EscribirDatosEstudiante {

    /**
     * Web service operation
     */
    @WebMethod(operationName = "escribeDatosPersonales")
    public String escribeDatosPersonales(@WebParam(name = "estnombre") String estnombre, @WebParam(name = "estapellido") String estapellido, @WebParam(name = "estcedula") String estcedula, @WebParam(name = "estcorreo") String estcorreo, @WebParam(name = "estcontrasena") String estcontrasena, @WebParam(name = "modinscrito1") String modinscrito1, @WebParam(name = "modinscrito2") String modinscrito2, @WebParam(name = "modinscrito3") String modinscrito3, @WebParam(name = "modinscrito4") String modinscrito4, @WebParam(name = "numestilo") String numestilo, @WebParam(name = "trimestre") String trimestre, @WebParam(name = "perfil") String perfil) throws Exception {
        String tema = " ";
        String var = " ";


        try {
            OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

            File file = new File("C://OntoDominio.owl");
            OWLOntology ont = manager.loadOntologyFromOntologyDocument(file);

            OWLDataFactory fac = manager.getOWLDataFactory();
            IRI ontologyIRI = manager.getOntologyDocumentIRI(ont);



            OWLDataFactory factory = manager.getOWLDataFactory();

            //Informacion PERSONAL del estudiante
            
            OWLClass Estudiante = factory.getOWLClass(IRI.create(ontologyIRI + "#Estudiante"));
          //  OWLClass Profesor = factory.getOWLClass(IRI.create(ontologyIRI + "#Profesor"));
            OWLClass Modulo = factory.getOWLClass(IRI.create(ontologyIRI + "#Modulo"));
            
             OWLObjectProperty elEstudianteTieneApellido = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneApellido"));
                                 
            OWLObjectProperty elEstudianteTieneCedula = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneCedula"));
             
             OWLObjectProperty elEstudianteTieneCorreo = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneCorreo"));
             
             OWLObjectProperty elEstudianteTieneContrasena = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneContrasena"));
             
            //Informacion de la CARRERA del Estudiante 
             OWLObjectProperty elEstudianteTieneModuloInscrito = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneModuloInscrito"));

             OWLObjectProperty elEstudianteTieneModuloVisto = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneModuloVisto"));
             
             OWLObjectProperty elEstudianteTieneModuloPorVer = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneModuloPorVer"));
             
             OWLObjectProperty elEstudianteTieneEstiloDeAprendizaje = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTieneEstiloDeAprendizaje"));
             
              OWLObjectProperty elEstudianteInscribioTrimestre = factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteInscribioTrimestre"));
             
              OWLObjectProperty elEstudianteTienePerfil= factory.getOWLObjectProperty(IRI.create(ontologyIRI
                + "#elEstudianteTienePerfil"));
              
           OWLIndividual estudiante = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + estnombre));

            OWLClassAssertionAxiom classAssertionAx = factory.getOWLClassAssertionAxiom(
                    Estudiante, estudiante);

            manager.addAxiom(ont, classAssertionAx);

            OWLIndividual apellido = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + estapellido));
            
            OWLIndividual cedula = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + estcedula));
            
            OWLIndividual correo= factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + estcorreo));
            
            OWLIndividual contrasena = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + estcontrasena));

            OWLIndividual moduloinscrito1 = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + modinscrito1));
            
            OWLIndividual moduloinscrito2 = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + modinscrito2));
            
            OWLIndividual moduloinscrito3 = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + modinscrito3));
            
            OWLIndividual moduloinscrito4 = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + modinscrito4));
            
            OWLIndividual numerostilo = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + numestilo));  
            
            OWLIndividual numerotrimestre = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + trimestre));
            
            OWLIndividual perfildeestudio = factory.getOWLNamedIndividual(IRI.create(ontologyIRI
                    + "#" + perfil));
            
            OWLObjectPropertyAssertionAxiom axiom1 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneApellido, estudiante, apellido);


            AddAxiom addAxiom1 = new AddAxiom(ont, axiom1);

            manager.applyChange(addAxiom1);
            
            

            OWLObjectPropertyAssertionAxiom axiom2 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneCedula, estudiante, cedula);


            AddAxiom addAxiom2 = new AddAxiom(ont, axiom2);

            manager.applyChange(addAxiom2);

            
            OWLObjectPropertyAssertionAxiom axiom3 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneCorreo, estudiante, correo);


            AddAxiom addAxiom3 = new AddAxiom(ont, axiom3);

            manager.applyChange(addAxiom3);
            
            OWLObjectPropertyAssertionAxiom axiom4 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneContrasena, estudiante, contrasena);


            AddAxiom addAxiom4 = new AddAxiom(ont, axiom4);

            manager.applyChange(addAxiom4);
            
            OWLObjectPropertyAssertionAxiom axiom5 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneModuloInscrito, estudiante, moduloinscrito1);


            AddAxiom addAxiom5 = new AddAxiom(ont, axiom5);

            manager.applyChange(addAxiom5);
            
               OWLObjectPropertyAssertionAxiom axiom6 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneModuloInscrito, estudiante, moduloinscrito2);


            AddAxiom addAxiom6 = new AddAxiom(ont, axiom6);

            manager.applyChange(addAxiom6);
            
             OWLObjectPropertyAssertionAxiom axiom7 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneModuloInscrito, estudiante, moduloinscrito3);


            AddAxiom addAxiom7 = new AddAxiom(ont, axiom7);

            manager.applyChange(addAxiom7);
            
             OWLObjectPropertyAssertionAxiom axiom8 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneModuloInscrito, estudiante, moduloinscrito4);


            AddAxiom addAxiom8 = new AddAxiom(ont, axiom8);

            manager.applyChange(addAxiom8);
            
            OWLObjectPropertyAssertionAxiom axiom9 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTieneEstiloDeAprendizaje, estudiante, numerostilo);


            AddAxiom addAxiom9 = new AddAxiom(ont, axiom9);

            manager.applyChange(addAxiom9);
            
            OWLObjectPropertyAssertionAxiom axiom10 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteInscribioTrimestre, estudiante, numerotrimestre);


            AddAxiom addAxiom10 = new AddAxiom(ont, axiom10);

            manager.applyChange(addAxiom10);
            
            OWLObjectPropertyAssertionAxiom axiom11 = factory
                    .getOWLObjectPropertyAssertionAxiom(elEstudianteTienePerfil, estudiante, perfildeestudio);


            AddAxiom addAxiom11 = new AddAxiom(ont, axiom11);

            manager.applyChange(addAxiom11);
            
            manager.saveOntology(ont, IRI.create(file));





        } catch (UnsupportedOperationException exception) {
            System.out.println("Unsupported reasoner operation.");
//		} catch (OWLOntologyCreationException e) {
//			System.out.println("Could not load the pizza ontology: "
//					+ e.getMessage());
//		}


        }
        var = var.replace("http://www.semanticweb.org/usuario/ontologies/2013/3/ontologiadedominio#", "\n");
        var = var.replace("_", " ");
        return var;

    }
}
